﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
    xmlns:controls="http://schemas.panthernet.ru/graphx/">

    <LinearGradientBrush x:Key="NormalBrush"
                         EndPoint="0.5,1"
                         StartPoint="0.5,0"
                         po:Freeze="true">
        <GradientStop Color="#FFFFFFFF" Offset="0"/>
        <GradientStop Color="#FFA4ADBB" Offset="0.521"/>
        <GradientStop Color="#FFD7E0EA" Offset="0.194"/>
        <GradientStop Color="#FFBAC1CF" Offset="0.811"/>
        <GradientStop Color="#FFBCC5D5" Offset="0.507"/>
        <GradientStop Color="#FFE3E4E6" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="NormalBorderBrush"
                         EndPoint="0.5,0"
                         StartPoint="0.5,1"
                         po:Freeze="true">
        <GradientStop Color="#FF8B8B8B"/>
        <GradientStop Color="#FFADADAD" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="EdgeBrush"
                         EndPoint="0.5,0"
                         StartPoint="0.5,1"
                         po:Freeze="true">
        <GradientStop Color="Black"/>
        <GradientStop Color="Gray" Offset="1"/>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="EdgeArrowBrush" Color="Black" po:Freeze="true" />

    <!-- VERTEX CONTROL -->
    <Style TargetType="{x:Type controls:VertexControl}">
        <!-- Set background color through attached property -->
        <Setter Property="Background" Value="{StaticResource NormalBrush}"/>
        <Setter Property="Padding" Value="10,5,10,5"/>
        <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
        <Setter Property="BorderThickness" Value="3"/>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:VertexControl}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="HoverOn">
                            <DoubleAnimation Duration="00:00:00.1000000"
                                             Storyboard.TargetName="BackgroundOver"
                                             Storyboard.TargetProperty="Opacity"
                                             To="1" />
                            <DoubleAnimation Duration="00:00:00.1000000"
                                             Storyboard.TargetName="BackgroundOver_Highlight"
                                             Storyboard.TargetProperty="Opacity"
                                             To="0.65" />
                        </Storyboard>
                        <Storyboard x:Key="HoverOff">
                            <DoubleAnimation Duration="00:00:00.4000000"
                                             Storyboard.TargetName="BackgroundOver"
                                             Storyboard.TargetProperty="Opacity"
                                             To="0" />
                            <DoubleAnimation Duration="00:00:00.4000000"
                                             Storyboard.TargetName="BackgroundOver_Highlight"
                                             Storyboard.TargetProperty="Opacity"
                                             To="0" />
                        </Storyboard>
                    </ControlTemplate.Resources>

                    <Grid>
                        <Border x:Name="BackgroundNorm"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="5"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"/>
                        <Border x:Name="BackgroundNorm_highlight"
                                Margin="1"
                                BorderBrush="{DynamicResource NormalHighlightBrush}"
                                BorderThickness="1,0,1,1"
                                CornerRadius="5"
                                Opacity="0.65" />
                        <Border x:Name="BackgroundOver"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="5"
                                Opacity="0"
                                Background="{DynamicResource MouseOverBrush}"
                                BorderBrush="{DynamicResource MouseOverBorderBrush}"/>
                        <Border x:Name="BackgroundOver_Highlight"
                                Margin="1"
                                BorderThickness="1,0,1,1"
                                CornerRadius="5"
                                Opacity="0"
                                BorderBrush="{DynamicResource MouseOverHighlightBrush}"/>

                        <Grid UseLayoutRounding="True"
                              SnapsToDevicePixels="True">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            
                            <TextBlock Text="{Binding Name}"
                                       VerticalAlignment="Center"
                                       TextAlignment="Center"
                                       HorizontalAlignment="Center"
                                       FontWeight="Bold"
                                       Foreground="Black"
                                       Grid.Column="1"
                                       Grid.Row="0"
                                       Margin="3"
                                       MinWidth="120"/>
                            
                            <TextBlock Text="{Binding Location}"
                                       TextAlignment="Center"
                                       FontStyle="Italic"
                                       FontSize="14"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       Foreground="White"
                                       Grid.Column="1"
                                       Grid.Row="1"
                                       Margin="3"/>
                        </Grid>
                    </Grid>
                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"
                                 Value="true">
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource HoverOff}"
                                                 x:Name="HoverOff_BeginStoryboard" />
                            </Trigger.ExitActions>
                            
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource HoverOn}" />
                            </Trigger.EnterActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>

        </Setter>

        <!-- VERTEX DRAGGING CONTROL -->
        <Setter Property="controls:DragBehaviour.IsDragEnabled"
                Value="True" />
        <Setter Property="controls:DragBehaviour.UpdateEdgesOnMove"
                Value="True" />

        <Style.Triggers>
            <Trigger Property="controls:HighlightBehaviour.Highlighted"
                     Value="True">
                <Setter Property="BorderBrush" Value="Gold"/>
                <Setter Property="BorderThickness" Value="2"/>
            </Trigger>
        </Style.Triggers>

    </Style>

    <!-- EDGE CONTROL -->
    <Style TargetType="{x:Type controls:EdgeControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:EdgeControl}">
                    <Grid>
                        <Path Stroke="{StaticResource EdgeBrush}"
                              StrokeThickness="2"
                              MinWidth="1"
                              MinHeight="1"
                              ToolTip="{TemplateBinding ToolTip}"
                              x:Name="PART_edgePath"/>
                        
                        <controls:DefaultEdgePointer NeedRotation="true"
                                                     x:Name="PART_EdgePointerForTarget">
                            <Path Data="M0,0.5 L1,1 1,0"
                                  Fill="Black"
                                  Stretch="Uniform"
                                  Width="15"
                                  Height="15"/>
                        </controls:DefaultEdgePointer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="MinWidth"
                Value="1" />
        <Setter Property="MinHeight"
                Value="1" />
        <Setter Property="Background"
                Value="Red" />
        <Setter Property="Foreground"
                Value="Silver" />
        <Setter Property="Opacity"
                Value="1" />
        
        <Setter Property="controls:HighlightBehaviour.IsHighlightEnabled" Value="True"/>

        <Style.Triggers>
            <Trigger Property="controls:HighlightBehaviour.Highlighted" Value="True">
                <Setter Property="Foreground" Value="Gold"/>
                <Setter Property="StrokeThickness" Value="1"/>
            </Trigger>
            
            <Trigger Property="controls:HighlightBehaviour.Highlighted" Value="False ">
                <Setter Property="Foreground" Value="Silver"/>
                <Setter Property="StrokeThickness" Value="1"/>
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>